home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 250 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.1 KB

  1. From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
  2. Message-ID: <9602020740.22411@mulga.cs.mu.OZ.AU>
  3. X-Original-Date: Fri, 2 Feb 1996 18:40:50 +1100
  4. Path: in2.uu.net!bounce-back
  5. Date: 03 Feb 96 04:43:34 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: #ifdef XXXX 
  9. Organization: Computer Science, University of Melbourne, Australia
  10. References: <1996Feb1.092058.4745@iiasa.ac.at>
  11. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  12.     iQBFAgUBMRLoA+EDnX0m9pzZAQFXDwGAkf7rkyUiF0uE9bfttCEJbeumqyePcSLe
  13.     QQD4Lk2HXGcbQekih+Km8Pt+2mVthRKK
  14.     =dqH9
  15.  
  16. marek@iiasa.ac.at (Marek  MAKOWSKI) writes:
  17.  
  18. >Would not it be sensible to add to the preprocessing a directive
  19. >that would stop processing the current file ?
  20.  
  21. I don't think it would be very useful.
  22.  
  23. >Something like
  24. >
  25. >#ifdef XXXX
  26. >#exit
  27. >
  28. >this would safe processing (sometimes very long) file in the common
  29. >situations:
  30. >
  31. >#ifdef XXXX
  32. >// a (possibly) long header file hear
  33. >#endif  /* ifdef XXXX*/
  34.  
  35. There is one situation in which this is very common: headers that
  36. are guarded against multiple inclusion:
  37.  
  38.     #ifndef FOO_H
  39.     #define FOO_H
  40.     ... code for foo.h ...
  41.     #endif
  42.  
  43. With your proposal, this could be rewritten as
  44.  
  45.     #ifdef FOO_H
  46.     #exit
  47.     #endif
  48.     #define FOO_H
  49.     ... code for foo.h ...
  50.  
  51. However, implementations can (and some do) optimize the processing of
  52. files using the standard guard technique so that they are only read
  53. when necessary.  This optimization actually improves performance more
  54. than your `#exit' would, because it avoids even opening the file the
  55. second and subsequent times.
  56.  
  57. `#exit' is not necessary for performance; adding `#exit' would not improve
  58. performance for already existing code; and use of `#exit' would require
  59. four preprocessor directives to guard include files rather than the three
  60. required by the standard guard idiom.  So I think adding `#exit' would be
  61. a bad idea.
  62.  
  63. --
  64. Fergus Henderson                 WWW: http://www.cs.mu.oz.au/~fjh
  65. fjh@cs.mu.oz.au                  PGP: finger fjh@128.250.37.3
  66. ---
  67. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  68.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  69.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  70.